<template>
  <div class="basic_setting">
      <el-form
        :model="form"
        :rules="rules"
        ref="basicForm"
        label-width="100px"
        label-position="top"
      >
        <el-form-item label="名称" prop="name">
          <el-input placeholder="请输入流程名称" v-model="form.name"></el-input>
        </el-form-item>
        <el-form-item label="分组" prop="groupId">
          <el-select
            style="width: 100%"
            v-model="form.groupId"
            placeholder="请选择流程分组"
          >
            <el-option
              v-for="(item, index) in form.groupList"
              :key="index"
              :label="item.groupName"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="业务绑定" prop="business">
          <el-cascader
            style="width: 100%;"
            placeholder="请选择与该流程绑定的业务"
            :options="form.businessList"
            v-model="form.business"
            filterable
          ></el-cascader>
        </el-form-item>
        <el-form-item label="备注" prop="decs">
          <el-input
            type="textarea"
            :rows="4"
            placeholder="这个人很懒，什么也没留下~"
            v-model="form.decs"
          ></el-input>
        </el-form-item>
        <!-- <el-form-item label="流程管理员">
          <div class="tips">
            备注：该管理员用户此流程最高权限，任何节点审批均可操作
          </div>
          <el-tag closable type="success">{{ form.admin }}</el-tag>
        </el-form-item> -->
      </el-form>
    </div>
</template>

<script>
import { listModelMenu, getModelGroupList } from "@/api/model";

export default {
  data() {
    return {
      form: {
        name: "新建模型",
        groupId: "",
        groupName: "",
        business: "",
        decs: "",
        businessList: [],
        groupList: [],
        // admin: "李时珍",
      },
      rules: {
        name: [{ required: true, message: "请输入流程名称", trigger: "blur" }],
        groupId: [
          { required: true, message: "请选择流程分组", trigger: "blur" },
        ],
        business: [
          {
            required: true,
            message: "请选择与该流程绑定的业务",
            trigger: "blur",
          },
        ],
      },
    };
  },
  methods: {
    validateForm() {
      let flag = "";
      this.$refs.basicForm.validate((valid) => {
        if (valid) {
          flag = this.form;
        } else {
          console.log("error submit!!");
          flag = false;
        }
      });
      let item = this.form.groupList.find((e) => e.id === this.form.groupId);
      this.form.groupName = item.groupName;
      return flag;
    },
    listMenuApi() {
      listModelMenu().then((res) => {
        if (res.code === 200) {
          this.form.businessList = res.data.map((item) => {
            return {
              label: item.menuName,
              value: item.menuId,
            };
          });
        }
      });
    },
    //分组列表
    getModelGroupListApi() {
      getModelGroupList().then((res) => {
        if (res.code === 200) {
          this.form.groupList = res.rows;
        }
      });
    },
  },
  created() {
    this.getModelGroupListApi();
    this.listMenuApi();
  },
};
</script>

<style lang="scss" scoped>
.basic_setting {
    margin: 10px auto;
    width: 50%;
    height: 100%;
    .item {
      margin: 20px 0;
    }
    .tips {
      font-size: 12px;
      color: rgb(235, 47, 47);
    }
}
</style>
